package com.weipt.lambda;

/**
 * @author peter.wei 2020/09/28 16:10
 * @version 1.0
 * @company 终生学习
 * @description <br>peter.wei 2020/09/28 16:10
 **/


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 题目要求：一分钟内完成此题，只能用一行代码实现！
 * 现在有5个用户！筛选：
 * 1、ID 必须是偶数
 * 2、年龄必须大于23岁
 * 3、用户名转为大写字母
 * 4、用户名字母倒着排序
 * 5、只输出一个用户！
 */
public class Hello01 {

    public static void main(String[] args) {
        User user1 = new User(1,12,"peter1");
        User user2 = new User(2,41,"peter2");
        User user3 = new User(3,42,"peter3");
        User user4 = new User(4,56,"peter4");
        User user5 = new User(5,11,"peter5");

        List<User> users = Arrays.asList(user1, user2, user3, user4, user5);

        Stream<String> limit = users.stream()
                .filter(t -> t.getId() % 2 == 0)  //Predicate函数接口
                .filter(m -> m.getAge() > 23)
                .map(e -> e.getName().toUpperCase())  //Function接口
                .sorted(Comparator.reverseOrder())
                .limit(1);
        System.out.println(limit.collect(Collectors.joining()));
    }
}


@Data
@AllArgsConstructor
@NoArgsConstructor
class User implements Serializable {

    private static final long serialVersionUID = 1L;

    private Integer id;
    private Integer age;
    private String name;
}